package com.rxt.common.result;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * 全局统一的返回结果类
 */
@NoArgsConstructor
@AllArgsConstructor
@Data
public class Result implements Serializable {
    // 状态码
    private Integer code;
    // 返回消息
    private String msg;
    // 返回数据
    private Object data;

    public static Result ok() {
        return new Result(
                ResultCodeEnum.SUCCESS.getCode(),
                ResultCodeEnum.SUCCESS.getMessage(),
                null
        );
    }

    public static Result ok(Object data) {
        return new Result(
                ResultCodeEnum.SUCCESS.getCode(),
                ResultCodeEnum.SUCCESS.getMessage(),
                data
        );
    }

    public static Result fail() {
        return new Result(
                ResultCodeEnum.FAIL.getCode(),
                ResultCodeEnum.FAIL.getMessage(),
                null
        );
    }

    public static Result fail(String msg) {
        return new Result(
                ResultCodeEnum.FAIL.getCode(),
                msg,
                null
        );
    }

    public static Result fail(Integer code, String msg) {
        return new Result(
                code,
                msg,
                null
        );
    }

    public static Result fail(ResultCodeEnum resultCodeEnum) {
        return new Result(
                resultCodeEnum.getCode(),
                resultCodeEnum.getMessage(),
                null
        );
    }
}
